function setEvents() {

	try {
		$id("btnClose").addEventListener("click", function() {
			pagesManager.hidePage();
		});
	} catch(xhr) {
	}

	$id("product").addEventListener("click", function() {

		callProductListService();
	});

	$id("addNewBook").addEventListener("click", function() {
		pagesManager.setPage(Pages.addNewProduct, false);
	});

	$id("bookHotView").addEventListener("click", function() {
		searchHotBook();
	});

	$id("outOfBook").addEventListener("click", function() {
		searchOutOfBook();
	});

	$id("btnSearchBook").addEventListener("click", function() {
		searchBook();
	});

	$id("category").addEventListener("click", function() {

		pagesManager.setPage(Pages.manageCategory, false);
	});

	$id("addNewCategory").addEventListener("click", function() {
		pagesManager.setPage(Pages.addNewCategory, false);
	});

	$id("user").addEventListener("click", function() {

		callServiceStaff();
	});

	$id("btnSearchStaff").addEventListener("click", function() {
		searchStaff();
	});

	$id("getAdmin").addEventListener("click", function() {
		getAllAdmin();
	});

	$id("getStaff").addEventListener("click", function() {
		getAllStaff();
	});

	$id("addNewUser").addEventListener("click", function() {
		pagesManager.setPage(Pages.addNewUser, false);
	});

	$id("customer").addEventListener("click", function() {

		callServiceCustomer();
	});

	$id("btnSearchCustomer").addEventListener("click", function() {
		searchCustomer();
	});

	$id("invoice").addEventListener("click", function() {
		callInvoiceService();
	});

	$id("btnSearchOrder").addEventListener("click", function() {
		searchOrder();
	});

	$id("feedback").addEventListener("click", function() {
		callFeedbackService();
	});

	$id("btnSearchFeedback").addEventListener("click", function() {
		searchFeedback();
	});

	$id("newFeedBack").addEventListener("click", function() {
		filterUnReaded();
	});

	$id("oldFeedback").addEventListener("click", function() {
		filterReaded();
	});

	$id("btnAdminLogin").addEventListener("click", function() {
		var userName = $id("txtAccountAdmin").value;
		var passWord = $id("txtPwdAdmin").value;
		doLogin(userName, passWord);
	});
	$id("logOutAdmin").addEventListener("click", function(event) {
		event.preventDefault();
		ajax.get({
			url : "http://localhost:8080/book-service/public/book/authen/logout",
			success : function(data, xhr) {
				var key = "";
				addActive(key);
				$id("loginAdminPage").addClass("modal");
				$id("loginAdminPage").removeClass("hidden");
			},
			failure : function(xhr) {
			},
			abort : function(xhr) {
				callback.abort(xhr);
			}
		});
	});
}

function doLogin(userName, password) {
	ajax.post({
		url : "http://localhost:8080/book-service/public/book/authen/login",
		param : {
			"userName" : userName,
			"passWord" : password
		},

		success : function(data, xhr) {
			console.log(data);

			$id("loginAdminPage").removeClass("modal");
			$id("loginAdminPage").addClass("hidden");
			$id("adminId").innerText = userName;
			callProductListService();
			//var key = "product";
			//addActive(key);
			//do setPageWellcome

		},
		failure : function(xhr) {
			alert("Tài khoản hoặc mật khẩu của bạn không đúng\n Xin thử lại")
		},
		abort : function(xhr) {
			callback.abort(xhr);
		}
	});
}
